package com.ruoyi.web.controller.qiushi.system;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.qiushi.domain.system.QiushiTaskRecord;
import com.ruoyi.qiushi.service.system.IQiushiTaskRecordService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务完成记录Controller
 *
 * @author ruoyi
 * @date 2024-01-16
 */
@RestController
@RequestMapping("/qiushi/system/qiushitaskrecord")
public class QiushiTaskRecordController extends BaseController {
    @Autowired
    private IQiushiTaskRecordService qiushiTaskRecordService;

    /**
     * 查询任务完成记录列表
     */
    @PreAuthorize("@ss.hasPermi('qiushi:system:qiushitaskrecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(QiushiTaskRecord qiushiTaskRecord) {
        startPage();
        List<QiushiTaskRecord> list = qiushiTaskRecordService.selectQiushiTaskRecordList(qiushiTaskRecord);
        return getDataTable(list);
    }

    /**
     * 导出任务完成记录列表
     */
    @PreAuthorize("@ss.hasPermi('qiushi:system:qiushitaskrecord:export')")
    @Log(title = "任务完成记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, QiushiTaskRecord qiushiTaskRecord) {
        List<QiushiTaskRecord> list = qiushiTaskRecordService.selectQiushiTaskRecordList(qiushiTaskRecord);
        ExcelUtil<QiushiTaskRecord> util = new ExcelUtil<QiushiTaskRecord>(QiushiTaskRecord.class);
        util.exportExcel(response, list, "任务完成记录数据");
    }

    /**
     * 获取任务完成记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('qiushi:system:qiushitaskrecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(qiushiTaskRecordService.selectQiushiTaskRecordById(id));
    }

    /**
     * 新增任务完成记录
     */
    @PreAuthorize("@ss.hasPermi('qiushi:system:qiushitaskrecord:add')")
    @Log(title = "任务完成记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QiushiTaskRecord qiushiTaskRecord) {
        qiushiTaskRecord.setUpdateTime(new Date());
        return toAjax(qiushiTaskRecordService.insertQiushiTaskRecord(qiushiTaskRecord));
    }

    /**
     * 修改任务完成记录
     */
    @PreAuthorize("@ss.hasPermi('qiushi:system:qiushitaskrecord:edit')")
    @Log(title = "任务完成记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QiushiTaskRecord qiushiTaskRecord) {
        return toAjax(qiushiTaskRecordService.updateQiushiTaskRecord(qiushiTaskRecord));
    }

    /**
     * 删除任务完成记录
     */
    @PreAuthorize("@ss.hasPermi('qiushi:system:qiushitaskrecord:remove')")
    @Log(title = "任务完成记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(qiushiTaskRecordService.deleteQiushiTaskRecordByIds(ids));
    }
}
